package com.it.emall.controller;

import com.github.pagehelper.PageHelper;
import com.it.emall.domain.Ingredients;
import com.it.emall.service.IngredientsService;
import com.it.emall.utils.ResponseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 分类controller
 */
@RestController
@RequestMapping("wx/ingredients")
public class IngredientsController {


    @Autowired
    private IngredientsService ingredientsService;

    @GetMapping("/index")
    public Object ingredients(){
        List<Ingredients> level1List = ingredientsService.selectLevel1List();
        Ingredients current=level1List.get(0);
        List<Ingredients> currentChildren = ingredientsService.selectChildrenListByPid(current.getId());
        Map<String,Object> data=new HashMap<>();
        data.put("ingredientsList",level1List);
        data.put("currentIngredients",current);
        data.put("currentSubIngredients",currentChildren);
        return ResponseUtils.ok(data);

    }


    /**
     * 查询指定分类以及子分类
     * @return
     */
    @GetMapping("/current")
    public Object children(Integer id){

        Ingredients current = ingredientsService.selectIngredientsById(id);

        List<Ingredients> ingredients1 = ingredientsService.selectChildrenListByPid(current.getId());

        Map<String,Object> data=new HashMap<>();
        data.put("currentIngredients",current);
        data.put("currentSubIngredients",ingredients1);
        return ResponseUtils.ok(data);



    }

}
